package com.example.byNight;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class ContextMenu extends Activity implements OnItemSelectedListener {

	File path = null;
	Spinner spinner;
	String[] paths;
	Button back, reset;
	EditText testo;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.contextmenu);
		// back= (Button) findViewById (R.id.back);
		// reset= (Button) findViewById (R.id.reset);
		testo = (EditText) findViewById(R.id.textCerca);
		Intent intent = getIntent();
		paths = intent.getStringArrayExtra("paths");

		String[] stringhe;
		String[] id = new String[paths.length];
		for (int i = 0; i < paths.length; i++) {
			stringhe = paths[i].split(";");
			for (int j = 0; j < stringhe.length; j++) {
				System.out.println(stringhe[j]);
				if (j == 0) {
					id[i] = stringhe[j];
					testo.setText(stringhe[j]);
				}
			}
		}

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
				ContextMenu.this, android.R.layout.simple_spinner_item, id);
		spinner = (Spinner) findViewById(R.id.spinner2);
		spinner.setAdapter(adapter);
		spinner.setOnItemSelectedListener(this);
	}

	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		int position = spinner.getSelectedItemPosition();
		if (position != 0) {
			Intent intent = new Intent(getApplicationContext(),
					Visualizza.class);
			intent.putExtra("ris", paths[position]);
			System.out.println("paths[positional] = " + paths[position]);
			startActivity(intent);
			finish();
		}
	}

	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
	}

}
